package com.snow.campuslink.lostFound.controller;


import com.snow.campuslink.annotation.RequestLog;
import com.snow.campuslink.lostFound.converter.dto.UpdateLostFoundActionCountDto;
import com.snow.campuslink.lostFound.entity.LostFoundPost;
import com.snow.campuslink.lostFound.service.ILostFoundPostService;
import com.snow.campuslink.project.constant.Enum.ModuleEnum;
import com.snow.campuslink.project.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.snow.campuslink.utils.ParamCheckUtil.checkValidResult;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Gaosl
 * @since 2021-02-12
 */
@RestController
@RequestMapping("/lostFound/lost-found-post")
public class LostFoundPostController {

    @Resource
    ILostFoundPostService lostFoundPostService;

    @ApiOperation(value = "")
    @RequestLog(module = ModuleEnum.BBS_POST,description = "")
    @PostMapping("lostFoundPost")
    public Result searchBbsPost(){
        return Result.success();
    }

    @ApiOperation(value = "")
    @GetMapping("getLostFoundPost/{lfPostId}")
    public Result getBbsPost(@PathVariable("lfPostId") Long lfPostId){
        LostFoundPost byId = lostFoundPostService.getById(lfPostId);
        return Result.success().data(byId);
    }

    @ApiOperation(value = "")
    @PostMapping("releaseLostFoundPost")
    public Result releaseGoodsWant(@RequestBody LostFoundPost lostFoundPost){
        boolean save = lostFoundPostService.save(lostFoundPost);
        if (!save) {
            return Result.fail();
        }
        return Result.success();
    }

    @ApiOperation("")
    @DeleteMapping("deleteBbsPost/{bbsPostId}")
    public Result removeById (@PathVariable("bbsPostId") Long bbsPostId){
        boolean b = lostFoundPostService.removeById(bbsPostId);
        if (!b) {
            return Result.fail();
        }
        return Result.success();
    }

    @ApiOperation("Feign接口")
    @PutMapping("updateActionCount")
    public void updateActionCount(@Validated @RequestBody UpdateLostFoundActionCountDto updateLostFoundActionCountDto, BindingResult result){
        checkValidResult(result);
        lostFoundPostService.updateActionCount(updateLostFoundActionCountDto);
    }

}

